# -*- coding: UTF-8 -*-
"""
@Project ：swift-forge-engine 
@File    ：menu_schema.py
@IDE     ：PyCharm 
@Author  ：Tony.Gan
@Date    ：2025/2/24 1:13 
@Des     ：
"""
from datetime import datetime

from pydantic import Field, ConfigDict

from App.common.schema import SchemaBase
from App.utils.enums import MenuType, StatusType


class MenuSchemaBase(SchemaBase):
    name: str
    parent_id: int | None = Field(default=None, description='菜单父级ID')
    sort: int = Field(default=0, ge=0, description='排序')
    icon: str | None = None
    path: str | None = None
    level: int | None = None
    menu_type: MenuType = Field(default=MenuType.directory.value, description='菜单类型（0目录 1菜单 2按钮）')
    component: str | None = None
    perms: str | None = None
    status: StatusType = Field(default=StatusType.enable.value)
    show: StatusType = Field(default=StatusType.enable.value)
    cache: StatusType = Field(default=StatusType.enable.value)
    remark: str | None = None


class CreateMenuParam(MenuSchemaBase):
    pass


class UpdateMenuParam(MenuSchemaBase):
    id: int
    pass


class GetMenuListDetails(MenuSchemaBase):
    model_config = ConfigDict(
        from_attributes=True,
        json_encoders={
            datetime: lambda v: v.strftime("%Y-%m-%d %H:%M:%S")
        }
    )

    id: int
    created_time: datetime
    updated_time: datetime | None = None
